// File Name:   data_mem.v
// Author:      Cody Cziesler
// Description: A configurable read-writable data memory

`include "include.v"

module data_mem #(parameter AWIDTH = 7,
                            DWIDTH = 16)
(
  input  wire                clka,
  input  wire                ena,
  input  wire                wea,
  input  wire  [AWIDTH-1:0]  addra,
  input  wire  [DWIDTH-1:0]  dina,
  output wire  [DWIDTH-1:0]  douta
);

parameter DEPTH = (1 << AWIDTH);

reg [DWIDTH-1:0] douta_r;
reg [DWIDTH-1:0] dmem [0:DEPTH-1];

assign douta = (ena) ? douta_r : {DWIDTH{1'b0}};

always @(posedge clka) begin
  if (wea && ena) begin
    dmem[addra] <= dina;
  end else begin
    douta_r     <= dmem[addra];
  end
end

endmodule
